package com.fyt.ZhongYaoApp.Controller;


import com.fyt.ZhongYaoApp.pojo.Result;
import com.fyt.ZhongYaoApp.pojo.ZYCat;
import com.fyt.ZhongYaoApp.service.ZYCatService;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/zycat")
@Tag(name = "ZYCat",description = "the ZYCat API") // 接口大标题
public class ZYCatController {

    @Autowired
    private ZYCatService zyCatService;

    @PostMapping("/add")
    public Result add(@RequestBody ZYCat zyCat) {

        // 如果种类已经存在
        if (zyCatService.findByZYCatName(zyCat.getCatName()) != null) {
            return Result.error("中药种类已经存在");
        }

        zyCatService.add(zyCat);

        return Result.success("中药种类添加成功");
    }

    @GetMapping("/getNameById")
    public Result<String> getNameById(@RequestBody ZYCat zyCat) {

        return Result.success(zyCatService.getNameById(zyCat));
    }

    @GetMapping("/list")
    public Result<List<ZYCat>> zyCatlList() {


        List<ZYCat> list = zyCatService.zyCatList();
        return Result.success(list);
    }
}











